package com.comp7940.groupf.tgbot.controller;

import com.comp7940.groupf.tgbot.builder.ResultBuilder;
import com.comp7940.groupf.tgbot.entity.User;
import com.comp7940.groupf.tgbot.entity.common.Result;
import com.comp7940.groupf.tgbot.redis.RedisCache;
import com.comp7940.groupf.tgbot.service.UserService;
import com.comp7940.groupf.tgbot.util.CodeUtil;
import com.comp7940.groupf.tgbot.util.EmailUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@Slf4j
@RestController                 // 返回json格式的数据
@CrossOrigin                    // 允许跨域
@RequestMapping("api/user")   // 下级目录
public class UserController {
    @Autowired
    private UserService us;
    @Autowired
    private RedisCache redisCache;
    @PostMapping("su-a")
    public Result<Boolean> suA(@RequestBody User args) {
        return ResultBuilder.buildSuccess(us.suA(args));
    }
    @PostMapping("check")
    public Result<Boolean> check(@RequestBody Map<String, Object> args) {
        return ResultBuilder.buildSuccess(us.check(args));
    }
    @PostMapping("su-e")
    public Result<Boolean> suE(@RequestBody User args) {
        return ResultBuilder.buildSuccess(us.suE(args));
    }
    @PostMapping("test")
    public Result<Boolean> test(@RequestBody Map<String, Object> args) {
        Boolean status = redisCache.getCacheObject((String) args.get("tgacc"));
        return ResultBuilder.buildSuccess(status != null && status);
    }
}
